const localImgInfo = {}; //  网络图片通过getImageInfo 加载到本地
var baseConfig = require("../../baseConfig");
Page({
    data: {
        canvasWidth: 750,
        canvasHeight: 1280,
        ma_img: wx.getStorageSync('ma_url'), // 二维码
        // avatarUrl: wx.getStorageSync('userInfo').avatarUrl, // 默认头像
        avatarUrl: '/static/icon/logo.png', // 默认头像
        hImg: '/static/2.png', // 顶图
        user: {},
        showPhone: '0',
        tuserInfo: {
            head: "/static/douyinlogo.png",
            nickname: "- -",
            phone: "******",
            integral: 0.00,
            totalIntegral: 0.00,
            masterName: "- -",
            masterHead: null,
            wxnum: "******",
            mywxnum: "******",
            groupPeople: 0,
            todaySum: 0.00,
            yestodaySum: 0.00,
            ddcommission: 0,
            groupbuild: 0,
            dynum: 0,
            incomes: 0,
            totalIncomes: 0,
            phoneDialogHidenAble: !1
        },
        appVersion: true,
        updatePhone: {
            phone: "",
            mywxnum: ""
        },
        head: wx.getStorageSync('userInfo').avatarUrl,
        nickname: wx.getStorageSync('userInfo').nickname,
        userRole: '',
        csmsg: "",
        integral: '0.00',
        totalIncomes: '0.00',
        todaySum: '0.00',
        yestodaySum: '0.00',
        layer1Popup: false,
        layer2Popup: false,
        layer3Popup: false,
        layer4Popup: false,
        isGetSet: true,
        isVip: '',
        getCaptcha: true,
        second: 60,
        poster: false,
    },
    onLoad: function () {
        const phone = wx.getStorageSync('tuserInfo').phone;
        this.setData({
            phone
        })
        console.log(phone);
        const user = wx.getStorageSync('userInfo');
        if (user) {
            this.setData({
                user: user
            })
            this.getLocalAvatar(user.avatarUrl);
        }
        let isVip = wx.getStorageSync('tuserInfo').role
        console.log(isVip);
        let head = wx.getStorageSync('tuserInfo').head
        if (head == undefined) {
            console.log("isVip:", isVip)
            this.setData({
                layer4Popup: true
            })
            this.init()
        } else {
            wx.setStorage({
                key: 'isVip',
                data: isVip,
            })
            this.get_tuserInfo()
            this.setData({
                isVip
            })
        }
    },
    onShow() {
        this.init();
    },
    getLocalAvatar: function (avatar) {
        // console.log('111', avatar);
        wx.getImageInfo({
            src: avatar,
            success: function (res) {
                // 保存到本地数组
                localImgInfo['avatarUrl'] = res.path;
                console.log('222', localImgInfo);
            },
            fail: (err) => {
                console.log(err);
            }
        })
    },
    createImg: function () {
        wx.showLoading({
            title: '图片生成中...',
        });
        setTimeout(this.drawCanvas, 500)
    },
    drawCanvas: function () {
        const _this = this;
        const {
            avatarUrl,
            canvasWidth,
            canvasHeight,
            hImg
        } = this.data;
        const ctx = wx.createCanvasContext('canvas');
        // const canvas_width = canvasWidth;
        // 背景色
        ctx.setFillStyle('#FF1718');
        ctx.fillRect(0, 0, canvasWidth, canvasHeight);
        // 绘制头图
        ctx.drawImage(hImg, 0, 0, canvasWidth, canvasHeight);
        // 绘制头像
        ctx.save(); // 先保存状态 已便于画完圆再用
        ctx.beginPath(); //开始绘制
        const avatarWidth = 180; // 头像宽度
        const avatarCenterY = 160; // 头像中心Y坐标
        ctx.arc(canvasWidth / 2, avatarCenterY, avatarWidth / 2, 0, Math.PI * 2, false);
        ctx.setFillStyle('#eeeeee');
        ctx.fill();
        ctx.clip();
        ctx.drawImage(localImgInfo['avatarUrl'] || avatarUrl, (canvasWidth - avatarWidth) / 2, avatarCenterY - avatarWidth / 2, avatarWidth, avatarWidth);
        ctx.restore(); //恢复之前保存的绘图上下文 恢复之前保存的绘图上下午即状态 可以继续绘制
        // 绘制用户名
        ctx.setFontSize(42);
        ctx.setFillStyle("#000");
        const nickNameText = this.data.nickname;
        ctx.fillText(nickNameText, (canvasWidth - ctx.measureText(nickNameText).width) / 2, 300);
        ctx.restore();
        // 底部二维码
        console.log(localImgInfo);
        console.log(avatarUrl);
        const ma_img = wx.getStorageSync('ma_url');
        // console.log(ma_img);
        // wx.getFileSystemManager()
        let fs = wx.getFileSystemManager()
        try {
            fs.mkdirSync(`${wx.env.USER_DATA_PATH}/resource`, false)
        } catch (e) {
            console.error(e)
        }
        this.QRCodeSrc = ma_img
        fs.writeFile({
            filePath: `${wx.env.USER_DATA_PATH}/resource/demo.png`,
            data: this.QRCodeSrc,
            encoding: 'base64',
            success(res1) {
                // console.log('writeFile:', res1)
                wx.getImageInfo({
                    src: `${wx.env.USER_DATA_PATH}/resource/demo.png`,
                    success(res) {
                        // console.log('getImageInfo:', res)
                        // this.ctx.drawImage('http://usr/resource/demo.png', 12, 384, 80, 80);
                        ctx.save(); // 先保存状态 已便于画完圆再用
                        ctx.beginPath(); //开始绘制
                        const maWidth = 180; // 二维码宽度
                        const maArcWidth = 180; // 二维码外层宽度
                        const maCenterY = canvasHeight - 200 - maWidth / 2; // 图片中心Y坐标
                        ctx.arc(150, maCenterY, maArcWidth / 2, 0, Math.PI * 2, false);
                        // ctx.arc(canvasWidth / 2, maCenterY, maArcWidth / 2, 0, Math.PI * 2, false);
                        ctx.fill();
                        ctx.clip();
                        ctx.setFillStyle('#dddddd') // 二维码白色底色
                        ctx.fillRect((canvasWidth - maArcWidth) / 2, maCenterY - maArcWidth / 2, maArcWidth, maArcWidth)
                        ctx.drawImage(res.path, 60, maCenterY - maWidth / 2, maWidth, maWidth);
                        ctx.save();
                        // ctx.restore(); //恢复之前保存的绘图上下文 恢复之前保存的绘图上下文即状态 可以继续绘制
                        // 绘制图片

                        ctx.draw(false, function () {
                            // 延时生成图片 否则真机测试文字会样式混乱
                            setTimeout(() => {
                                // 生成图片
                                wx.canvasToTempFilePath({
                                    canvasId: 'canvas',
                                    success: res => {
                                        wx.hideLoading();
                                        _this.setData({
                                            close_hb: true
                                        })
                                        _this.createShareImgSuccess(res.tempFilePath);
                                    },
                                    fail: () => {
                                        wx.showToast({
                                            title: '图片生成失败~',
                                            icon: 'none'
                                        });
                                    }
                                })
                            }, 1000)
                        })
                    },
                    fail(err) {
                        console.error(err)
                        // this.ctx.drawImage('http://usr/resource/demo.png', 12, 384, 80, 80);
                    }
                })
            },
            fail(err) {
                console.error(err)
            }
        })

    },
    createShareImgSuccess: function (tempFilePath) {
        // const _this = this;
        this.setData({
            showPoster: true,
            tempShareImg: tempFilePath,
        });
    },
    getImg() {
        const _this = this;
        wx.saveImageToPhotosAlbum({
            filePath: this.data.tempShareImg,
            success(res) {
                wx.showToast({
                    title: '图片已保存至相册，快去分享吧!',
                    icon: 'none',
                    duration: 3000,
                })
            },
            // 保存到相册失败
            fail: function (err) {
                console.log(err);
                if (err.errMsg === "saveImageToPhotosAlbum:fail cancel") {
                    _this.saveShareImgErr();
                } else if (err.errMsg === "saveImageToPhotosAlbum:fail:auth denied" || err.errMsg === "saveImageToPhotosAlbum:fail auth deny" || err.errMsg === "saveImageToPhotosAlbum:fail authorize no response") {
                    wx.showModal({
                        title: '温馨提示',
                        content: '请开启保存到相册权限，开启后自动保存相册',
                        success(res) {
                            if (res.confirm) {
                                wx.openSetting({
                                    success(settingdata) {
                                        if (settingdata.authSetting['scope.writePhotosAlbum']) {
                                            _this.createShareImgSuccess(tempFilePath);
                                        } else {
                                            _this.saveShareImgErr();
                                        }
                                    }
                                })
                            } else if (res.cancel) {
                                _this.saveShareImgErr();
                            }
                        }
                    })
                } else {
                    console.log('111');
                    _this.saveShareImgErr();
                }
            }
        })
    },
    saveShareImgErr: function () {
        wx.showToast({
            title: '图片保存失败~ ',
            icon: 'none',
            duration: 3000,
        })
    },
    getMa() {
        console.log('11111111111111111111');
        wx.request({
            url: baseConfig.baseUrl + 'get_wx_mini_qr_code',
            method: 'GET',
            header: {
                'Content-Type': 'application/x-www-form-urlencoded',
                "UID": wx.getStorageSync("userid")
                // "UID": '230'
            },
            success: res => {
                // console.log(res.data.data);
                this.setData({
                    ma_url: res.data.data
                });
                wx.setStorageSync('ma_url', this.data.ma_url)
                // console.log(this.data.ma_url);
            }
        })
    },
    getPoster() {
        this.setData({
            poster: true
        })
        this.createImg()
    },
    closePoster() {
        this.setData({
            poster: false
        })
        this.getImg()
    },
    closeMb() {
        if(this.data.close_hb){
            this.setData({
                poster: false
            })
        }
        this.setData({
            close_hb: false
        })
        
    },
    setTuserInfo() {
        let isVip = wx.getStorageSync('tuserInfo').role
        let mywxnum = wx.getStorageSync('tuserInfo').mywxnum
        this.setData({
            isVip,
            mywxnum,
        });
        if (isVip == 'USER') {
            this.setData({
                change: 0,
            })
        }
    },
    saveNum() {
        console.log(this.data.phone);
        let that = this;
        wx.request({
            url: baseConfig.baseUrl + `users/bind_user_phone`,
            method: 'POST',
            data: {
                phone: this.data.phone,
            },
            header: {
                'content-type': 'application/json',
                "UID": wx.getStorageSync("userid")
            },
            success: (res) => {
                console.log(res.data.data);
                if (res.data.data.error) {
                    console.log(res.data.data.msg);
                    this.showMsg(res.data.data.msg);
                } else {

                    wx.setStorage({
                        key: 'newuserInfo',
                        data: res.data.data,
                    });
                    let userinfo = wx.getStorageSync('tuserInfo');
                    let phone = wx.getStorageSync('phone');
                    userinfo.role = res.data.data.role;
                    userinfo.phone = phone;
                    console.log(userinfo);
                    wx.setStorage({
                        key: 'tuserInfo',
                        data: userinfo
                    });
                    wx.setStorage({
                        key: 'isVip',
                        data: res.data.data.role,
                    })
                    that.setData({
                        isVip: res.data.data.role,
                        layer5Popup: false,
                        layer6Popup: true,
                        phone,
                    });
                }
            }
        });
    },
    numBlur(e) { // 检测三个input是否全部填完了
        console.log(e.detail.value);
        if (this.data.phone && this.data.mywxnum && this.data.captcha) {
            this.setData({
                numBlur: true,
                mywxnum: e.detail.value,
            })
            console.log(this.data.phone, this.data.mywxnum, this.data.captcha);
        } else {
            this.setData({
                mywxnum: e.detail.value,
                numBlur: false
            })
            console.log(this.data.phone, this.data.mywxnum, this.data.captcha);
        }
    },
    getCaptcha() { // 点击获取验证码
        let that = this
        console.log('点击获取验证码');
        if (this.data.phone) {
            console.log(that.data.phone);
            let phoneReg = /^1[3456789]\d{9}$/
            if (phoneReg.test(this.data.phone)) {
                this.timer();
                this.setData({
                    getCaptcha: false,
                });
                wx.request({
                    url: baseConfig.baseUrl + `send_message_code`,
                    method: 'GET',
                    data: {
                        phone: this.data.phone,
                    },
                    header: {
                        'content-type': 'application/json',
                        "UID": wx.getStorageSync("userid")
                    },
                    success: (res) => {
                        console.log(res.data.data);
                        if (res.data.data.error !== '0') {
                            let msg = res.data.data.msg;
                            this.setData({
                                msg: msg,
                            });
                        } else {
                            console.log('验证码正确');
                        }
                    }
                });
            } else {
                this.showMsg("手机号格式有误 请检查");
            }
        } else {
            this.showMsg("请填写手机号！");
        }
    },
    timer: function () { // 倒计时
        let promise = new Promise((resolve, reject) => {
            let setTimer = setInterval(
                () => {
                    this.setData({
                        second: this.data.second - 1
                    })
                    if (this.data.second <= 0) {
                        this.setData({
                            getCaptcha: true
                        })
                        resolve(setTimer)
                    }
                }, 1000)
        })
        promise.then((setTimer) => {
            clearInterval(setTimer)
        })
    },
    toIndex() { // 前往首页
        wx.switchTab({
            url: '/pages/home/home',
        })
        this.setData({
            layer6Popup: false,
        })
    },
    get_tuserInfo() {
        let {
            nickname,
            mywxnum,
            // phone, // hzzj
            head,
            integral,
            totalIncomes,
            todaySum,
            yestodaySum,
        } = wx.getStorageSync('tuserInfo');

        // let integral1 = (integral).toFixed(2);
        let totalIncomes1 = (totalIncomes).toFixed(2);
        let todaySum1 = (todaySum).toFixed(2);
        let yestodaySum1 = (yestodaySum).toFixed(2);
        this.setData({
            nickname,
            mywxnum,
            // phone, // hzzj
            head,
            integral: integral,
            totalIncomes: totalIncomes1,
            todaySum: todaySum1,
            yestodaySum: yestodaySum1,
        })
    },
    init: function () {
        let that = this
        wx.login({
            success(res) {
                that.setData({
                    code: res.code
                })
                if (res.code) {
                    wx.request({
                        url: baseConfig.baseUrl + 'users/simpleInfo',
                        method: 'GET',
                        header: {
                            'Content-Type': 'application/x-www-form-urlencoded',
                            "UID": wx.getStorageSync("userid")
                        },
                        data: {
                            code: res.code
                        },
                        success: res => {
                            // console.log('login1phone1', wx.getStorageSync('tuserInfo').phone);
                            that.setData({
                                phone: wx.getStorageSync('tuserInfo').phone
                            })
                            wx.setStorage({
                                key: 'tuserInfo',
                                data: res.data.data,
                            })
                            that.get_tuserInfo()
                            that.setTuserInfo()
                        }
                    })
                } else {
                    console.log('登录失败！' + res.errMsg)
                }
            }
        })
    },
    getPhoneNumber1: function (e) { //点击获取手机号码按钮
        var that = this;
        wx.login({
            success(res) {
                that.setData({
                    code: res.code
                })
                if (res.code) {
                    wx.request({
                        url: baseConfig.baseUrl + 'users/code_to_session',
                        method: 'GET',
                        header: {
                            'Content-Type': 'application/x-www-form-urlencoded',
                            "UID": wx.getStorageSync("userid")
                        },
                        data: {
                            js_code: res.code
                        },
                        success: res => {
                            console.log(res.data.data);
                            var sessionk = res.data.data
                            wx.checkSession({
                                success: (res) => {
                                    var ency = e.detail.encryptedData;
                                    var iv = e.detail.iv;
                                    if (e.detail.errMsg == 'getPhoneNumber:fail user deny') {
                                        that.setData({
                                            modalstatus: true
                                        });
                                    } else { // 同意授权
                                        wx.setStorageSync('showPhone', '1')
                                        that.setData({
                                            showPhone: '1'
                                        })
                                        wx.request({
                                            method: "GET",
                                            url: baseConfig.baseUrl + 'get_phone',
                                            data: {
                                                encrypdata: ency,
                                                ivdata: iv,
                                                sessionkey: sessionk
                                            },
                                            header: {
                                                'Content-Type': 'application/json'
                                            },
                                            success: (res) => {
                                                console.log("解密成功~~~~将解密的号码保存到本地");
                                                console.log(res.data.data);
                                                var phone = res.data.data.phoneNumber;
                                                that.setData({
                                                    phone
                                                })
                                                wx.setStorageSync('phone', phone)
                                                that.saveNum()
                                            },
                                            fail: function (res) {
                                                console.log("解密失败~~~~~");
                                                console.log(res);
                                            }
                                        });
                                    }
                                },
                                fail: function () {
                                    console.log("session_key 已经失效，需要重新执行登录流程");
                                    that.login(1); //重新登录
                                }
                            });
                        },
                        fail: (err) => {
                            console.log(err);
                        }
                    })
                } else {
                    console.log('登录失败！' + res.errMsg)
                }
            }
        })
        // this.login

    },
    closeAuthDialog: function () {
        let that = this
        this.setData({
            layer4Popup: false
        })
        wx.getUserProfile({
            desc: '用于完善会员资料',
            success: function (res) {
                that.setData({
                    userInfo: res.userInfo
                })
                that.login()
            }
        })
        this.get_tuserInfo()
    },
    login(e) {
        console.log(e);
        let that = this
        var code = wx.getStorageSync('inviteCode')
        wx.request({
            url: baseConfig.baseUrl + 'users/login/wx',
            method: 'POST',
            header: {
                'Content-Type': 'application/json'
            },
            data: {
                inviteCode: code,
                u: that.data.userInfo,
                token: '',
                js_code: that.data.code
            },
            success: res => {
                // console.log(res.data.data);
                wx.setStorage({
                    key: 'userInfo',
                    data: res.data.data,
                })
                wx.setStorage({
                    key: 'userid',
                    data: res.data.data.id,
                })
                wx.setStorage({
                    key: 'openid',
                    data: res.data.data.openid,
                })
                wx.setStorage({
                    key: 'token',
                    data: res.data.data.token,
                })
                wx.setStorage({
                    key: 'isVip',
                    data: res.data.data.role,
                })
                that.setData({
                    uid: res.data.data.id,
                    isVip: res.data.data.role,
                })
                console.log(that.data.isVip);

                const user = wx.getStorageSync('userInfo');
                // console.log(user);
                if (user) {
                    this.setData({
                        user: user
                    })
                    // console.log(user.avatarUrl);
                    this.getLocalAvatar(user.avatarUrl);
                }
                that.simpleInfo()
                if (e == 1) {
                    this.getPhoneNumber1()
                }
            }
        })
    },
    simpleInfo() {
        let that = this
        wx.request({
            url: baseConfig.baseUrl + 'users/simpleInfo',
            method: 'GET',
            header: {
                'Content-Type': 'application/x-www-form-urlencoded'
            },
            data: {
                uid: that.data.uid
            },
            success: res => {
                console.log(res.data.data);
                wx.setStorage({
                    key: 'tuserInfo',
                    data: res.data.data,
                })
                that.setData({
                    nickname: res.data.data.nickname,
                    head: res.data.data.head,
                    mywxnum: res.data.data.mywxnum,
                    phone: res.data.data.phone,
                    integral: res.data.data.integral,
                    todaySum: res.data.data.todaySum.toFixed(2),
                    totalIncomes: res.data.data.totalIncomes.toFixed(2),
                    yestodaySum: res.data.data.yestodaySum.toFixed(2),
                })
                this.getMa()
            }
        })
    },
    copyMasterWxNum: function () {
        this.tuserInfo.wxnum ? e.setClipboardData({
            data: this.tuserInfo.wxnum,
            success: function () {
                e.showToast({
                    title: " 微信号已复制",
                    icon: "none"
                });
            }
        }) : this.showMsg("没有联系方式~");
    },
    copyID: function () {
        let id = wx.getStorageSync('userInfo').id
        wx.setClipboardData({
            data: id,
            success: function () {}
        });
    },
    showMainView: function (e) {
        i.config.version !== e && (console.log(i.config.version, e), this.appVersion = !0);
    },
    jumpToBalanceHistory: function () {
        let that = this
        let isVip = this.data.isVip
        if (isVip == 'USER') {
            wx.navigateTo({
                url: "/pages/myWallet/myWallet"
            });
        } else {
            console.log('前往成为会员');
            wx.showModal({
                title: '提示',
                content: '请先激活会员',
                success(res) {
                    if (res.confirm) {
                        //
                    } else if (res.cancel) {
                        console.log('用户点击取消')
                    }
                }
            })
        }
    },
    showUserMsg: function () { // 修改资料
        this.setData({
            layer3Popup: true
        })
    },
    bindInput1: function (e) {
        this.setData({
            mywxnum: e.detail.value
        })
    },
    bindInput2: function (e) {
        this.setData({
            phone: e.detail.value
        })
    },
    bindInput3: function (e) {
        this.setData({
            captcha: e.detail.value
        })
    },
    getPhoneNumber: function () { // 保存资料
        var that = this;
        let openid = wx.getStorageSync('openid')
        var uid = wx.getStorageSync("userid")
        let userInfo = wx.getStorageSync("userInfo")
        // console.log(openid, uid);
        console.log();
        if (this.data.mywxnum) {
            console.log(that.data.mywxnum);
            if (this.data.phone) {
                console.log(that.data.phone);
                this.setData({
                    layer3Popup: false
                })
                this.showMsg("绑定成功！");
                wx.request({
                    url: baseConfig.baseUrl + 'users/bindPhoneNoSecret/h5',
                    method: 'POST',
                    data: {
                        wxnum: that.data.mywxnum,
                        phone: that.data.phone,
                        uid: uid,
                        openid: openid
                    },
                    header: {
                        'Content-Type': 'application/json; charset=UTF-8'
                    },
                    success: res => {
                        console.log(res.data);
                        console.log(userInfo);
                        userInfo.mywxnum = that.data.mywxnum
                        userInfo.phone = that.data.phone
                        console.log(userInfo);
                        wx.setStorage({
                            data: userInfo,
                            key: 'userInfo',
                        })
                    },
                    fail: err => {
                        console.log(err);
                    }
                })
                console.log('123');
            } else {
                this.showMsg("请填写手机号！");
            }
        } else {
            this.showMsg("请填写微信号！");
        }
    },
    customBtnClick() { // 官方客服弹窗
        this.setData({
            layer2Popup: true
        })
    },
    savePhotoToAlbum2(res) { // 官方客服-保存到相册
        this.saveImageToPhotos2(res)
    },
    copyWxNum2() { // 复制微信号2
        // let wxnum = wx.getStorageSync('tuserInfo').wxnum
        wx.setClipboardData({
            // data: wxnum,
            data: 'logic-yuan',
            success: function (res) {
                wx.showToast({
                    title: "复制成功~",
                    icon: "none"
                });
            },
            fail: function (err) {
                console.log(err);
            }
        });
    },
    closeClick2() { // 关闭官方客服弹窗2
        this.setData({
            layer2Popup: false
        })
    },
    closeClick5() {
        this.setData({
            layer5Popup: false
        })
    },
    jumpTutorial() { // 新手教程
        wx.navigateTo({
            url: "/pages/ksnewCourse/ksnewCourse",
        });
    },
    jumpProblem() { // 常见问题
        wx.navigateTo({
            url: "../problem/problem"
        })
    },
    jumpTeam() { // 我的团队
        wx.navigateTo({
            url: "./team"
        })
    },

    groupBuildNow() { // 邀请好友
        let isVip = wx.getStorageSync('userInfo').role
        if (isVip == 'TEMPUSER') {
            console.log("isVip:", this.isVip)
            wx.showToast({
                title: "暂无权限，请激活会员开通该权限",
                icon: "none"
            })
        } else {
            wx.navigateTo({
                url: "/pages/extension/extension"
            });
        }
    },
    openVip() { // 开通会员
        wx.navigateTo({
            url: "/pages/openVip/openVip"
        });
    },
    openVipDialog() { // 开通会员弹窗
        this.setData({
            layer5Popup: true
        })
    },
    jumpKuaishouhao() { // 我的快手号
        if (wx.getStorageSync('tuserInfo').role != "USER") {
            wx.showModal({
                title: '提示',
                content: '请先激活会员',
                success(res) {}
            })
            return
        }
        wx.navigateTo({
            url: "/pages/douyinAccount/douyinAccount"
        });
    },
    profitReportClick() { // 收益报表
        if (wx.getStorageSync('userInfo').role != "USER") {
            wx.showModal({
                title: '提示',
                content: '请先激活会员',
                success(res) {
                    if (res.confirm) {
                        // return wx.navigateTo({
                        //   url: "/subPackage/pages/ksMe/ksMe"
                        // });
                    } else if (res.cancel) {
                        console.log('用户点击取消')
                    }
                }
            })
            return
        }
        wx.navigateTo({
            url: "/subPackage/pages/ksprofitReportForm/ksprofitReportForm"
        });
    },
    customBusinessBtnClick: function () { // 商务合作
        this.setData({
            layer2Popup: true
        })
    },
    aboutUs: function () { // 关于我们
        this.setData({
            layer1Popup: true
        })
    },
    closeClick: function () { // 关于我们 弹窗关闭
        this.setData({
            layer1Popup: false
        })
    },
    copyWxNum: function () { // 复制公众号
        wx.setClipboardData({
            data: "SuperExpert",
            success: function () {
                wx.showToast({
                    title: "复制成功~",
                    icon: "none"
                });
            }
        });
    },
    savePhotoToAlbum(res) { // 关于我们-保存到相册
        console.log(res)
        this.saveImageToPhotos(res)
    },
    // 保存图片相关函数方法 saveImage saveImage2 saveImageToPhotos saveImageToPhotos2
    saveImage(filePath) {
        wx.saveImageToPhotosAlbum({
            filePath: "/static/qrcode.jpg",
            success: (res) => {
                // console.log(res)
                wx.showToast({
                    title: '保存成功',
                    icon: "none"
                });
            },
            fail: (err) => {
                console.log(err)
                wx.showToast({
                    title: '保存失败',
                    icon: "none"
                });
            }
        })
    },
    saveImage2(filePath) {
        wx.saveImageToPhotosAlbum({
            filePath: "/static/lisa.jpg",
            success: (res) => {
                // console.log(res)
                wx.showToast({
                    title: '保存成功',
                    icon: "none"
                });
            },
            fail: (err) => {
                console.log(err)
                wx.showToast({
                    title: '保存失败',
                    icon: "none"
                });
            }
        })
    },
    saveImageToPhotos(filePath) {
        let that = this
        wx.getSetting({
            success: (res) => {
                if (!res.authSetting['scope.writePhotosAlbum']) {
                    wx.authorize({
                        scope: 'scope.writePhotosAlbum',
                        success: () => {
                            that.saveImage(filePath)
                            that.setData({
                                isGetSet: true,
                                layer1Popup: false
                            })
                            wx.showToast({
                                title: '保存图片至相册',
                                icon: 'success',
                                duration: 2000
                            })
                        },
                        fail: () => {
                            that.setData({
                                isGetSet: false
                            })
                        }
                    })
                } else {
                    that.setData({
                        isGetSet: true,
                        layer1Popup: false
                    })
                    that.saveImage(filePath)
                    wx.showToast({
                        title: '保存图片至相册',
                        icon: 'success',
                        duration: 2000
                    })
                }
            },
            fail: (res) => {
                console.log(res);
            }
        })
    },
    saveImageToPhotos2(filePath) {
        let that = this
        wx.getSetting({
            success: (res) => {
                if (!res.authSetting['scope.writePhotosAlbum']) {
                    wx.authorize({
                        scope: 'scope.writePhotosAlbum',
                        success: () => {
                            that.saveImage2(filePath)
                            that.setData({
                                isGetSet: true,
                                layer1Popup: false
                            })
                            wx.showToast({
                                title: '保存图片至相册',
                                icon: 'success',
                                duration: 2000
                            })
                        },
                        fail: () => {
                            that.setData({
                                isGetSet: false
                            })
                        }
                    })
                } else {
                    that.setData({
                        isGetSet: true,
                        layer1Popup: false
                    })
                    that.saveImage2(filePath)
                    wx.showToast({
                        title: '保存图片至相册',
                        icon: 'success',
                        duration: 2000
                    })
                }
            },
            fail: (res) => {
                console.log(res);
            }
        })
    },
    showMsg: function (n) { // 轻提示方法
        wx.showToast({
            title: n,
            icon: "none"
        });
    },
    onShareAppMessage: function () {
        var uid = wx.getStorageSync('userid')
        return {
            title: "@来给我组队一起赚收益，提现金吧！",
            imageUrl: "http://fcdn.qiushilaile.com/tuiwa/tuiwa-24091628160723955.jpg",
            path: "pages/home/home?id=" + uid
        }
    }
})